package com.gee.spring.boot.rpf.service.impl;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.gee.spring.boot.rpf.controller.ClientController;
import com.gee.spring.boot.rpf.controller.fico.RequestWrapper;
import com.gee.spring.boot.rpf.controller.fico.request.CreRequest;
import com.gee.spring.boot.rpf.controller.fico.response.FiCoResponse;
import com.gee.spring.boot.rpf.service.FiCoService;
import com.gee.thread.flow.executor.ExecuteContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * desc:
 *
 * @author gee wrote on  2021-02-03 17:23:46
 */
@Service
public class FiCoServiceImpl implements FiCoService {

    private final Logger logger = LoggerFactory.getLogger(ClientController.class);

    @Override
    public ExecuteContext<RequestWrapper> credit(CreRequest creRequest) {
        String clientFlowId = getClientFlowId(creRequest);
        long start = System.currentTimeMillis();
        ExecuteContext<RequestWrapper> executeContext = commonExecuteClient(clientFlowId, creRequest);
        long cost = System.currentTimeMillis() -start;

        logger.info("cost: {} execute: {}", cost, JSONUtil.toJsonStr(executeContext));
        return executeContext;
    }

    private String getClientFlowId(CreRequest creRequest){
        //TODO 根据服务请求参数 获取 ClientFlowId
        return "3";
    }
}
